import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.glu.GLU;

/**
 * Created by WheelChen on 2017/5/19.
 */
public class Line3d implements GLEventListener {
    GLU glu = new GLU();
    private float rtri = 0.0f;
    @Override
    public void init(GLAutoDrawable glAutoDrawable) {

    }

    @Override
    public void dispose(GLAutoDrawable glAutoDrawable) {

    }

    @Override
    public void display(GLAutoDrawable drawable) {
        final GL2 gl = drawable.getGL().getGL2();

        gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT );
        gl.glLoadIdentity();                       // Reset The View
        gl.glTranslatef( 0f, 0f, -2.5f );
        gl.glRotatef( rtri, 0.0f, 1.0f, 0.0f );
        gl.glBegin( GL2.GL_LINES );
        gl.glVertex3f( -0.75f,0f,0 );
        gl.glVertex3f( 0f,-0.75f, 0 );
        gl.glEnd();

        //3d line
        gl.glBegin( GL2.GL_LINES );
        gl.glVertex3f( -0.75f,0f,-1f );// 3 units into the window
        gl.glVertex3f( 0f,-0.75f,-1f );
        gl.glEnd();

        gl.glFlush();
        rtri +=1f;
    }

    @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL2 gl = drawable.getGL().getGL2();
        if( height <=0 )
            height =1;
        final float h = ( float ) width / ( float ) height;
        gl.glViewport( 0, 0, width, height );
        gl.glMatrixMode( GL2.GL_PROJECTION );
        gl.glLoadIdentity();
        glu.gluPerspective( 45.0f, h, 1.0, 20.0 );
        gl.glMatrixMode( GL2.GL_MODELVIEW );
        gl.glLoadIdentity();
    }
}
